<?php
use think\Db;
use think\Loader;
function txtest(){
	return "testText110";
}

/***
*
*磅房相关函数
*
***/


/***
*
*获取用户列表
*
***/
function getUserList(){
	$list = Db::name('users')->where(array('dataFlag'=>1))->field("userId,userName,power,dataFlag,isManager")->select();
	if(empty($list)){
		$list = array();
	}
	$data['status'] = 1;
	$data['msg'] = 'ok';
	$data['data'] = $list;
	return $list;
}


/***
*
*获取榜房列表
*
***/
function getHouseList(){
	$list = Db::name('house')->where(array('dataFlag'=>1))->select();
	if(empty($list)){
		$list = array();
	}
	return $list;
}

/***
*
*获取榜房信息
*
***/
function getHouseById($id){
    if(empty($id)){
        return array();
    }
    $list = Db::name('house')->where(array('dataFlag'=>1,'houseId'=>$id))->find();
    if(empty($list)){
        return array();
    }
    return $list;
}

/***
*
*配置相关函数
*
***/


/***
*
*获取配置列表
*
***/
function getConfig($id=0){
	if($id > 0){
		$list = Db::name('config')->where(array('dataFlag'=>1,'configId'=>$id))->find();
	}else{
		$where['dataFlag'] = 1;
		$list = Db::name('config')->where($where)->select();
	}
	if(empty($list)){
		$list = array();
	}
	return $list;
}


function getAllConfig(){
    $list = Db::name('config')->alias('c')->join("__HOUSE__ h","c.houseId=h.houseId")->where("c.dataFlag=1")->field("c.configId,c.company,c.codeLeft,c.backupUrl,c.weighModel,c.normalLen,c.tempLen,c.printHead,c.printEnd,c.dataFlag,c.houseId,c.codeType,c.codeLen,c.portName,c.baudRate,c.dataBit,c.checkBit,c.stopBit,c.cacheLen,h.houseName,c.isTest,c.isDebug,c.codePagearea,c.codePrintarea,c.reportPagearea,c.reportPrintarea,c.pageName,c.cacheLen,c.timeAreareport,c.video,c.cameraIp,c.cameraPort,c.cameraUser,c.cameraPwd,c.picUrl,c.weighInterval,c.serverPicurl")->select();
    if(empty($list)){
        $list = array();
    }
    return $list;
}

/***
*
*根据磅房ID获取配置信息
*
***/
function getConfigByHouse($id){
	if($id > 0){
		$list = Db::name('config')->where(array('dataFlag'=>1,'houseId'=>$id))->find();
	}else{
		$list = array();
	}
	if(empty($list)){
		$list = array();
	}
	return $list;
}

/***
*
*客户相关函数
*
***/

/***
*
*获取客户列表
*
***/
function getCustomerList($houseId=0){
	$list = Db::name('customer')->where(array('dataFlag'=>1))->select();
	if(empty($list)){
		$list = array();
		return $list;
	}
	if($houseId > 0){
		$rs = array();
		foreach($list as $k => $v){
			$tmp = explode(',',$v['receiveHouse']);
			if(in_array($houseId,$tmp)){
				$rs[] = $v;
			}
		}
		return $rs;
	}else{
		return $list;
	}
}


/***
*
*构机相关函数
*
***/

/***
*
*获取钩机号列表
*
***/
function getExcavatorList(){
	$list = Db::name('excavator')->where(array('dataFlag'=>1))->select();
	if(empty($list)){
		$list = array();
	}
	return $list;
}

/***
*
*创建当天流水号
*
***/
function createSerialNumber($d){
	$rs = Db::name('serialnumber')->insert(array('serialDate'=>$d,'serialNumber'=>1));
	return $rs;
}

/***
*
*自增当天流水号
*
***/
function writeSerialNumber($d){
	$str = "update tx_serialnumber set serialNumber=serialNumber+1 where serialDate='" . $d . "'";
	$rs = Db::name('serialnumber')->query($str);
	return $rs;
}

/***
*
*获取当天流水号
*
***/
function getSerialNumber(){
	$dstr = date('Y-m-d');
    $number = 1;
    $tmp = Db::name('serialnumber')->where(array('serialDate'=>$dstr))->find();
    if(empty($tmp)){
        $rs = createSerialNumber($dstr);
        if($rs > 0){
            $number = 1;
        }else{
            $data['status'] = -1;
            $data['msg'] = '创建流水号失败';
            $data['data'] = '';
            return $data;
            exit;
        }
    }else{
        $rs = writeSerialNumber($dstr);
        if($rs <= 0){
            $data['status'] = -1;
            $data['msg'] = '写入流水号失败';
            $data['data'] = '';
            return $data;
            exit;
        }
        $number = $tmp['serialNumber'] + 1;

    }
    $str = str_pad($number,4,0,STR_PAD_LEFT);
    $data['status'] = 1;
    $data['msg'] = 'ok';
    $data['data'] = $str;
    return $data;
}





/***
*
*发运路线相关函数
*
***/

/***
*
*获取发运路线列表
*
***/

function getRouteList(){
    $list = Db::name('route')->where(array('dataFlag'=>1))->select();
    if(empty($list)){
        $list = array();
    }
    return $list;
}


/***
*
*发货位置相关函数
*
***/

/***
*
*获取发货位置列表
*
***/

function getPositionList(){
    $list = Db::name('position')->alias('p')->join('__CUSTOMER__ c',"p.customerId=c.customerId")->field('p.positionId,p.position,p.customerId,p.dataFlag,c.customerName as unit')->where(array('p.dataFlag'=>1))->select();
    if(empty($list)){
        $list = array();
    }
    return $list;
}


/***
*
*获取物资列表
*
***/
function goodsList(){
	$list = Db::name('goods')->where(array('dataFlag'=>1))->select();
	if(empty($list)){
		$list = array();
	}
	return $list;
}

/***
*
*判断称重是否合法
*
***/
function scaleIsLegal($code,$houseId,$weightype=0){
	$where['truckCode'] = $code;
    $where['weigh'] = 00;
    $where['billDate'] = strtotime(date('Y-m-d',time()));
    $where['dataFlag'] = 1;
    /*$where['houseId'] = $houseId;注释以后表示所有磅房空车重量一样*/
    /*print_r($where);*/
    $bill = Db::name('weighbill')->where($where)->find();
    if(empty($bill) || $bill['weigh'] > 0){
    	return array('status'=>-1,'msg'=>'没有相关记录,合法','data'=>array());
    }else{
    	$emptyWeigh = $bill['emptyWeigh'];
        $fullWeigh = $bill['fullWeigh'];
        $weigh = $bill['weigh'];
        if($weightype == 0){
            if($fullWeigh > 0){
            	return array('status'=>0,'msg'=> $code . "&nbsp;已经保存毛重,请不要重复检重",'data'=>array());
            }
        }else{
            if($emptyWeigh > 0){
            	return array('status'=>0,'msg'=> $code . "&nbsp;已经保存皮重,请不要重复检皮",'data'=>array());
            }
        }
        return array('status'=>1,'msg'=>'ok','data'=>$bill);
    }
}

function getTruckTypeList(){
	$list = Db::name('trucktype')->select();
    if(empty($list)){
        $list = array();
    }
    return $list;
}

function getTruckCodeList(){
	$list = Db::name('truckcode')->select();
    if(empty($list)){
        $list = array();
    }
    return $list;
}

function getTruckList(){
	$list = Db::name('truck')->alias('t')->join('__TRUCKTYPE__ m',"t.truckType=m.typeId")->where(array('t.dataFlag'=>1))->field("t.truckId,t.truckCode,t.driver,t.truckOwner,t.truckType,t.emptyWeigh,t.weighDate,t.dataFlag,t.emptyOperator,t.houseId,m.typeName,m.maxWeigh")->select();
    if(empty($list)){
        $list = array();
    }else{
        foreach($list as $k => $v){
            $list[$k]['weighDateDesc'] = date('Y-m-d',$v['weighDate']);
        }
    }
    return $list;
}

function checkUserLogin($userName,$userPwd){
	$where['userName'] = $userName;
	$where['userPwd'] = $userPwd;
	$where['dataFlag'] = 1;
	$user = Db::name('users')->where($where)->find();
	if(empty($user)){
		$rs['status'] = -1;
		$rs['msg'] = '用户名或密码错误';
		$rs['data'] = array();
	}else{
		$rs['status'] = 1;
		$rs['msg'] = 'ok';
		unset($user['userPwd']);
		$rs['data'] = $user;
	}
	return $rs;
}

/***
*
*获取普通报表
*
***/
function normalReport($timeArea,$billDateStart,$billDateEnd,$billDate,$goodsName,$sendUnit,$receiveUnit,$fullOperator,$billCode,$truckCode,$position,$route,$excavator,$houseId,$md=0){
    $where = [];
    if($timeArea == 1){
        if(!empty($billDateStart)){
            $billDateStart = strtotime($billDateStart);
        }else{
            $billDateStart = strtotime(date('Y-m-d',time()) . ' ' . "00:00");
        }
        if(!empty($billDateEnd)){
            $billDateEnd = strtotime($billDateEnd);
        }else{
            $billDateEnd = strtotime(date('Y-m-d',time() + 86400) . ' ' . "00:00");
        }
    }
	if(!empty($billDate)){
        $billDate = strtotime($billDate);
    }else{
    	$billDate = strtotime(date('Y-m-d',time()));
    }
    if(!empty($fullOperator)){
    	$where['w.fullOperator'] = $fullOperator;
    }
    if(!empty($goodsName)){
        $where['w.goodsName'] = $goodsName;
    }
    if(!empty($sendUnit)){
        $where['w.sendUnit'] = $sendUnit;
    }
    if(!empty($receiveUnit)){
        $where['w.receiveUnit'] = $receiveUnit;
    }
    if(!empty($houseId)){
    	$where['w.houseId'] = $houseId;
    }
    if(!empty($billCode)){
        $where['w.billCode'] = $billCode;
    }
    if(!empty($position)){
        $where['w.position'] = $position;
    }
    if(!empty($route)){
        $where['w.route'] = $route;
    }
    if(!empty($excavator)){
        $where['w.excavator'] = $excavator;
    }
    if(!empty($truckCode)){
        $where['w.truckCode'] = $truckCode;
    }
    if($md == 0){
        $where['w.dataFlag'] = 1;
    }
    if($timeArea == 1){
        $str = '';
        foreach($where as $k => $v){
            if(!empty($v)){
                $str = $str . $k . " = '" . $v . "' and ";
            }
        }
        $str = $str . "w.emptyWeigh > 0 and w.fullWeigh > 0 and w.weigh > 0 and w.fullTime >= " . $billDateStart . " and w.fullTime < " . $billDateEnd;
        $rs = Db::name('weighbill')->alias('w')->join("__HOUSE__ h",'w.houseId=h.houseId')->where($str)->field('w.billId,w.billCode,w.billDate,w.goodsName,w.truckCode,w.driver,w.emptyWeigh,w.emptyTime,w.emptyOperator,w.fullWeigh,w.fullTime,w.fullOperator,w.weigh,w.sendUnit,w.receiveUnit,w.position,w.excavator,w.route,h.houseName,w.printCount,w.truckType,w.locked,w.picUrl,w.dataFlag')->order('billId ASC')->select();
    }else{
        $where['w.billDate'] = $billDate;
        $where['w.emptyWeigh'] = ['>',0];
        $where['w.fullWeigh'] = ['>',0];
        $where['w.weigh'] = ['>',0];
        $rs = Db::name('weighbill')->alias('w')->join("__HOUSE__ h",'w.houseId=h.houseId')->where($where)->field('w.billId,w.billCode,w.billDate,w.goodsName,w.truckCode,w.driver,w.emptyWeigh,w.emptyTime,w.emptyOperator,w.fullWeigh,w.fullTime,w.fullOperator,w.weigh,w.sendUnit,w.receiveUnit,w.position,w.excavator,w.route,h.houseName,w.printCount,w.truckType,w.locked,w.picUrl,w.dataFlag')->order('billId ASC')->select();
    }
    if(empty($rs)){
    	$rs = array();
    }
    return $rs;
}


/***
*
*修改密码及重置密码
*
***/
function setUserPwd($id,$pwd=""){
    if($pwd == ""){
        $pwd = md5('123456' . md5('123456'));
    }
    if(empty($id)){
        return false;
    }
    $d['userPwd'] = $pwd;
    $where['userId'] = $id;
    $rs = Db::name('users')->where($where)->update($d);
    return $rs;
}

/***
*
*检查密码是否正确
*
***/
function checkUserPwd($id,$pwd){
    $where['userId'] = $id;
    $where['userPwd'] = $pwd;
    $rs = Db::name('users')->where($where)->find();
    if(empty($rs)){
        return false;
    }else{
        return true;
    }
}


/***
*
*制作EXCEL表格
*
***/
function makeRport($arr=array(),$titleDesc=array(),$title=array(),$info=array('houseName'=>'','type'=>'')){
    Loader::import('phpexcel.PHPExcel.IOFactory');
    if(empty($title)){
        print_r('请输入表格标题');
        exit;
    }
    $excel = new \PHPExcel();
    $mj = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ');
    $letter = array();
    $letterDesc = array();
    for($s=0;$s<count($titleDesc);$s++){
        $letter[] = $mj[$s];
        $letterDesc[] = $title[$s];
    }
    for($i=0;$i< count($letter);$i++){
        $excel->getActiveSheet()->setCellValue($letter[$i] . '1',$titleDesc[$i]);
    }
    $row = 2;
    for($m=2;$m <= count($arr) + 1;$m++){
        $n = 0;
        foreach($arr[$m - 2] as $k => $v){
            $excel->getActiveSheet()->setCellValue($letter[$n] . $m,$arr[$m - 2][$letterDesc[$n]]);
            $n++;
        }
        
    }
    $filename = $info['houseName'] . date('Ymd',time()) . $info['type'] . '(' . $info['op'] . ')' . '.xls';
    $write = new \PHPExcel_Writer_Excel5($excel);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
    header("Content-Type:application/force-download");
    header("Content-Type:application/vnd.ms-execl");
    header("Content-Type:application/octet-stream");
    header("Content-Type:application/download");;
    header('Content-Disposition:attachment;filename="' . $filename .'"');
    header("Content-Transfer-Encoding:binary");
    $write->save('php://output');
    exit();
}


/***
*
*二维数组转字符串
*
***/

function takeArrayToString($arr){
    if(empty($arr)){
        return '';
    }
    $str = '';
    $atr = array();
    foreach($arr as $k => $v){
        $tmp = '';
        foreach($v as $kk => $vv){
            $tmp = $tmp . $kk . '=>' . $vv . '|';
        }
        $atr[] = substr($tmp,0,strlen($tmp) - 1);
    }
    $str = implode('^',$atr);

    return $str;
}


/***
*
*字符串转二维数组
*
***/

function takeStringToArray($str){
    if(empty($str)){
        return array();
    }
    $arr = array();
    $atr = explode('^',$str);
    foreach($atr as $k => $v){
        $tmparr = array();
        $tmp = explode('|',$v);
        foreach($tmp as $kk => $vv){
            $tm = explode('=>',$vv);
            if(count($tm) >= 2){
                $tmparr[$tm[0]] = $tm[1];
            }
        }
        if(!empty($tmparr)){
            $arr[] = $tmparr;
        }
    }
    return $arr;
}



/**
 * 上传文件
 */
function TXUploadFile(){
    $fileKey = key($_FILES);
    $dir = 'truckpictrue';
    $dr = Input('post.dir');
    $upname = Input('post.upname');
    if(!empty($dr)){
        $dir = $dr;
    }
    if($dir==''){
        $data['status'] = -1;
        $data['msg'] = '没有指定文件目录！';
        return $data;
    }
    /*$dirs = WSTConf("CONF.wstUploads");
    if(!in_array($dir, $dirs)){
        return json_encode(['msg'=>'非法文件目录！','status'=>-1]);
    }*/
    //上传文件
    $file = request()->file($fileKey);
    if($file===null){
        $data['status'] = -1;
        $data['msg'] = '上传文件不存在或超过服务器限制';
        return $data;
    }
    $validate = new \think\Validate([
        ['fileExt','fileMime:image/png,image/gif,image/jpeg,image/x-ms-bmp','只允许上传jpg,gif,png,bmp类型的文件'],
        ['fileExt','fileExt:jpg,jpeg,gif,png,bmp','只允许上传后缀为jpg,gif,png,bmp的文件'],
        ['fileSize','fileSize:2097152','文件大小超出限制'],
    ]);
    $data = ['fileMime'  => $file,
             'fileSize' => $file,
             'fileExt'=> $file
            ];
    if (!$validate->check($data)) {
        return ['msg'=>$validate->getError(),'status'=>-1];
    }
    $if = $file->getInfo();
    $info = $file->rule('uniqid')->move(ROOT_PATH.'/public/upload/'.$dir."/".date('Y-m-d'),$if['name']);
    //保存路径
    $filePath = $info->getPathname();
    $filePath = str_replace(ROOT_PATH,'',$filePath);
    $filePath = str_replace('\\','/',$filePath);
    $name = $info->getFilename();
    $filePath = str_replace($name,'',$filePath);
    if($info){
        $data['status'] = 1;
        $data['msg'] = 'ok';
        return $data;
    }else{
        //上传失败获取错误信息
        $data['status'] = -1;
        $data['msg'] = $file->getError();
        return $data;
    }
}

/***
*
*   手工补单
*
***/
function insertBillsByHand(){
    Loader::import('phpexcel.PHPExcel.IOFactory');
    Loader::import('phpexcel.PHPExcel.Reader.Excel5');
    $fileKey = key($_FILES);
    $file = request()->file($fileKey);
    if($file===null){
        $data['status'] = -2;
        $data['msg'] = '上传文件不存在或超过服务器限制';
        $data['data'] = [];
        $data['err'] = [];
        $data['test'] = $_FILES;
        return $data;
    }
    $validate = new \think\Validate([
        ['fileExt','fileMime:xlsx','只允许上传xlsx类型的文件'],
        ['fileExt','fileExt:xlsx','只允许上传后缀为xlsx的文件'],
        ['fileSize','fileSize:2097152','文件大小超出限制'],
    ]);
    $data = ['fileMime'  => $file,
             'fileSize' => $file,
             'fileExt'=> $file
            ];
    $if = $file->getInfo();
    $info = $file->validate(['ext'=>'xlsx'])->rule('uniqid')->move(ROOT_PATH.'/public/upload/insertbills/'.date('Y-m-d'),$if['name']);
    //保存路径
    $filePath = $info->getPathname();
    $filePath = str_replace(ROOT_PATH,'',$filePath);
    $filePath = str_replace('\\','/',$filePath);
    $name = $info->getFilename();
    $filePath = str_replace($name,'',$filePath);
    if($info){
        
        $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
        $file_name = ROOT_PATH . '/public/upload/insertbills/' . date('Y-m-d') . '/' . $if['name'];
        $obj_PHPExcel =$objReader->load($file_name, $encode = 'utf-8');
        $excel_array=$obj_PHPExcel->getsheet(0)->toArray();
        $houseId = session("TX_HOUSE.houseId");
        $config = getConfigByHouse($houseId);
        $arr = array();
        $err = array();
        if(count($excel_array) < 4){
            $data['status'] = -1;
            $data['msg'] = '数据为空,请正确输入数据';
            $data['data'] = $arr;
            $data['err'] = $err;
            return $data;
            exit;
        }
        $tm = $excel_array[1][2];
        if(empty($tm)){
            $data['status'] = -1;
            $data['msg'] = '请输入过磅日期';
            $data['data'] = $arr;
            $data['err'] = $err;
            return $data;
            exit;
        }
        $housese = getHouseList();
        for($i=3;$i<count($excel_array);$i++){
            $tam = $excel_array[$i];
            if(empty($tam[0])){
                break;
            }
            $ks = checkBillData($tam,$housese,$tm);
            if($ks['status'] == 1){
                $arr[] = $ks['data'];
            }else{
                $err[] = $ks['data'];
            }
        }
        if(!empty($arr)){
            foreach($arr as $k => $v){
                $num = getSerialNumber();
                if($num['status'] == -1){
                    $data['status'] = -1;
                    $data['msg'] = $v['truckCode'] . '->创建流水号失败';
                    $data['data'] = $data;
                    $data['error'] = $err;
                    return $data;
                    exit;
                }
                $codeLeft = $config['codeLeft'];
                $arr[$k]['billCode'] = $codeLeft . date('Ymd') . $num['data'];
            }
            $rs = Db::name('weighbill')->insertAll($arr);
            if(empty($rs)){
                $data['status'] = -1;
                $data['msg'] = '保存数据错误';
                $data['data'] = $rs;
                $data['err'] = $err;
                return $data;
                exit;
            }
            $data['status'] = 1;
            foreach($arr as $k => $v){
                $arr[$k]['billDateDesc'] = date('Y-m-d',$v['billDate']);
                $arr[$k]['emptyTimeDesc'] = date('H:i:s',$v['emptyTime']);
                $arr[$k]['fullTimeDesc'] = date('H:i:s',$v['fullTime']);
            }
            $data['msg'] = '保存数据成功';
            $data['data'] = $arr;
            $data['err'] = $err;
            return $data;
            exit;
        }else{
            $data['status'] = -1;
            $data['msg'] = '没有可补充的磅单';
            $data['data'] = $excel_array;
            $data['err'] = $err;
            return $data;
        }
    }else{
        //上传失败获取错误信息
        $data['status'] = -2;
        $data['msg'] = $file->getError();
        $data['data'] = [];
        $data['err'] = [];
        return $data;
    }
}

function checkBillData($arr=array(),$housese=array(),$d){
    if(empty($arr)){
        return false;
    }
    if(empty($housese)){
        return false;
    }
    $rs = array();
    $rs['truckCode'] = $arr[0];
    $rs['billDate'] = strtotime($d);
    if(empty($arr[1])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->司机姓名错误";
        return $data;
        exit;
    }else{
        $rs['driver'] = $arr[1];
    }
    if(empty($arr[2])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->物资名称错误";
        return $data;
        exit;
    }else{
        $rs['goodsName'] = $arr[2];
    }
    if(empty($arr[3])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->皮重错误";
        return $data;
        exit;
    }else{
        if(!is_numeric($arr[3])){
            $data['status'] = -1;
            $data['data'] = $arr[0] . "->皮重只能为数字";
            return $data;
            exit;
        }
        $rs['emptyWeigh'] = $arr[3];
    }
    if(empty($arr[4])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->毛重错误";
        return $data;
        exit;
    }else{
        if(!is_numeric($arr[4])){
            $data['status'] = -1;
            $data['data'] = $arr[0] . "->毛重只能为数字";
            return $data;
            exit;
        }
        $rs['fullWeigh'] = $arr[4];
    }
    if(empty($arr[5])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->净重错误";
        return $data;
        exit;
    }else{
        if(!is_numeric($arr[5])){
            $data['status'] = -1;
            $data['data'] = $arr[0] . "->净重只能为数字";
            return $data;
            exit;
        }
        $rs['weigh'] = $arr[5];
    }
    if(empty($arr[6])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->皮重过磅员错误";
        return $data;
        exit;
    }else{
        $rs['emptyOperator'] = $arr[6];
    }
    if(empty($arr[7])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->毛重过磅员错误";
        return $data;
        exit;
    }else{
        $rs['fullOperator'] = $arr[7];
    }
    if(empty($arr[8])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->检皮时间错误";
        return $data;
        exit;
    }else{
        $rs['emptyTime'] = strtotime($d . ' ' . $arr[8]);
    }
    if(empty($arr[9])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->检毛时间错误";
        return $data;
        exit;
    }else{
        $rs['fullTime'] = strtotime($d . ' ' . $arr[9]);
    }
    if(empty($arr[10])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->发货单位错误";
        return $data;
        exit;
    }else{
        $rs['sendUnit'] = $arr[10];
    }
    if(empty($arr[11])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->收货单位错误";
        return $data;
        exit;
    }else{
        $rs['receiveUnit'] = $arr[11];
    }
    $rs['position'] = $arr[12];
    $rs['route'] = $arr[13];
    if(empty($arr[14])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->磅房名称错误";
        return $data;
        exit;
    }else{
        $tma = 0;
        foreach($housese as $k=>$v){
            if($v['houseName'] == $arr[14]){
                $tma = $v['houseId'];
                break;
            }
        }
        if($tma <= 0){
            $data['status'] = -1;
            $data['data'] = $arr[0] . "->磅房名称与列表中不一致";
            return $data;
            exit;
        }else{
            $rs['houseId'] = $tma;
        }
    }
    if(empty($arr[15])){
        $data['status'] = -1;
        $data['data'] = $arr[0] . "->钩机号错误";
        return $data;
        exit;
    }else{
        $rs['excavator'] = $arr[15];
    }
    $rs['printCount'] = 0;
    $rs['dataFlag'] = 1;
    $rs['mem'] = '';
    $rs['truckType'] = '解放八轮';
    $rs['locked'] = 0;
    $data['status'] = 1;
    $data['data'] = $rs;
    return $data;
}

function FileUpload($f,$url){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_NOBODY, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, array('file'=>'@' . $f));
    $return_str = curl_exec($curl);
    curl_close($curl);
    return $return_str;
}



?>